using MicroMsg.Common.Utils;
using MicroMsg.Resource.@string;
using MicroMsg.UI.Page;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace MicroMsg.UI.UserContrl
{
	public class ProcessingCover : UserControl
	{
		private const string TAG = "ProcessingCover";
		private static ProcessingCover mProcessingCover;
		private static double currentProgressLength = 1.0;
		internal Grid LayoutRoot;
		internal TextBlock txBkTitle;
		internal PerformanceProgressBar progressBar;
		internal Button btnOk;
		internal Rectangle progress_outer;
		internal Border progress_inner;
		private bool _contentLoaded;
		private ProcessingCover()
		{
			ShowObjectInMemory.AddOneObjectRecord(this);
			this.InitializeComponent();
			this.LayoutRoot.set_Background(R.theme.COMMON_PROGRESS_COVER_BRUSH);
			this.txBkTitle.set_Text(strings.COM_Sending);
			this.progressBar.IsIndeterminate = true;
			this.LayoutRoot.set_Visibility(0);
		}
		private ProcessingCover(string strTitle)
		{
			ShowObjectInMemory.AddOneObjectRecord(this);
			this.InitializeComponent();
			this.LayoutRoot.set_Background(R.theme.COMMON_PROGRESS_COVER_BRUSH);
			this.txBkTitle.set_Text(strTitle);
			this.progressBar.IsIndeterminate = true;
			this.LayoutRoot.set_Visibility(1);
		}
		~ProcessingCover()
		{
			ShowObjectInMemory.RemoveOneObjectRecord(this);
		}
		public static ProcessingCover getProgressBar(Grid gridTarget, string strTitle = null, Brush backGroudBrush = null, bool showProgress = false, bool showOkButton = false, RoutedEventHandler btnOk_Click = null)
		{
			if (gridTarget == null)
			{
				BasePage rootPage = ToolFunction.GetRootPage();
				if (rootPage != null)
				{
					gridTarget = (rootPage.get_Content() as Grid);
				}
			}
			if (gridTarget == null)
			{
				return null;
			}
			if (ProcessingCover.mProcessingCover == null)
			{
				ProcessingCover.mProcessingCover = new ProcessingCover();
			}
			if (strTitle == null)
			{
				strTitle = strings.COM_Sending;
			}
			if (ProcessingCover.mProcessingCover.get_Parent() != null)
			{
				Grid grid = (Grid)ProcessingCover.mProcessingCover.get_Parent();
				grid.get_Children().Remove(ProcessingCover.mProcessingCover);
			}
			ProcessingCover.mProcessingCover.txBkTitle.set_Text(strTitle);
			Log.smethod_5("ProcessingCover", "showProgressBar");
			gridTarget.get_Children().Add(ProcessingCover.mProcessingCover);
			ToolFunction.SetAppBarVisibility(false);
			ProcessingCover.mProcessingCover.progress_outer.set_Visibility(showProgress ? 0 : 1);
			ProcessingCover.mProcessingCover.progress_inner.set_Visibility(showProgress ? 0 : 1);
			if (showOkButton)
			{
				ProcessingCover.mProcessingCover.btnOk.set_Visibility(0);
				ProcessingCover.mProcessingCover.btnOk.remove_Click(btnOk_Click);
				ProcessingCover.mProcessingCover.btnOk.add_Click(btnOk_Click);
			}
			ProcessingCover.currentProgressLength = 1.0;
			ProcessingCover.setSystemTrayColor();
			return ProcessingCover.mProcessingCover;
		}
		public static void setProgressBarTitle(Grid gridTarget, string strTitle = null, Brush backGroudBrush = null, bool showProgress = false, bool showOkButton = false, RoutedEventHandler btnOk_Click = null)
		{
			if (gridTarget == null)
			{
				BasePage rootPage = ToolFunction.GetRootPage();
				if (rootPage != null)
				{
					gridTarget = (rootPage.get_Content() as Grid);
				}
			}
			if (gridTarget == null)
			{
				return;
			}
			if (strTitle == null)
			{
				strTitle = strings.COM_Sending;
			}
			if (ProcessingCover.mProcessingCover != null && ProcessingCover.mProcessingCover.get_Parent() == gridTarget)
			{
				ProcessingCover.mProcessingCover.txBkTitle.set_Text(strTitle);
				if (showOkButton)
				{
					ProcessingCover.mProcessingCover.btnOk.set_Visibility(0);
					ProcessingCover.mProcessingCover.btnOk.remove_Click(btnOk_Click);
					ProcessingCover.mProcessingCover.btnOk.add_Click(btnOk_Click);
					return;
				}
			}
			else
			{
				ProcessingCover.getProgressBar(gridTarget, strTitle, backGroudBrush, showProgress, showOkButton, btnOk_Click);
			}
		}
		public static void releaseProgressBar(Grid gridTarget)
		{
			if (gridTarget == null)
			{
				BasePage rootPage = ToolFunction.GetRootPage();
				if (rootPage != null)
				{
					gridTarget = (rootPage.get_Content() as Grid);
				}
			}
			ProcessingCover.changeSystemTrayColorBack();
			if (gridTarget == null)
			{
				return;
			}
			if (gridTarget.get_Children().Contains(ProcessingCover.mProcessingCover))
			{
				if (ProcessingCover.mProcessingCover.btnOk.get_Visibility() == null)
				{
					ProcessingCover.mProcessingCover.btnOk.set_Visibility(1);
					gridTarget.get_Children().Remove(ProcessingCover.mProcessingCover);
					ProcessingCover.mProcessingCover = null;
				}
				else
				{
					gridTarget.get_Children().Remove(ProcessingCover.mProcessingCover);
				}
				ToolFunction.SetAppBarVisibility(true);
				Log.smethod_5("ProcessingCover", "releaseProgressBar");
			}
		}
		public static void setCurrentProgress(int percent)
		{
			Log.smethod_5("ProcessingCover", "Progress changed : " + percent);
			if (percent < 0)
			{
				percent = 100;
			}
			Storyboard loadStoryBoard = ProcessingCover.getLoadStoryBoard(percent);
			if (loadStoryBoard != null)
			{
				loadStoryBoard.Begin();
			}
			ProcessingCover.currentProgressLength += (double)percent / 20.0;
		}
		private static Storyboard getLoadStoryBoard(int percent)
		{
			if (ProcessingCover.mProcessingCover == null)
			{
				return null;
			}
			Storyboard storyboard = new Storyboard();
			DoubleAnimation doubleAnimation = new DoubleAnimation();
			doubleAnimation.set_From(new double?(ProcessingCover.currentProgressLength));
			doubleAnimation.set_To(new double?(ProcessingCover.currentProgressLength + (double)percent / 20.0));
			doubleAnimation.set_Duration(new Duration(new TimeSpan(0, 0, 2)));
			doubleAnimation.set_AutoReverse(false);
			Storyboard.SetTarget(doubleAnimation, ProcessingCover.mProcessingCover.progress_inner.get_RenderTransform());
			Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("ScaleX", new object[0]));
			storyboard.get_Children().Add(doubleAnimation);
			return storyboard;
		}
		private static void changeSystemTrayColorBack()
		{
		}
		private static void setSystemTrayColor()
		{
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/CommonUseControl/ProcessingCover.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.txBkTitle = (TextBlock)base.FindName("txBkTitle");
			this.progressBar = (PerformanceProgressBar)base.FindName("progressBar");
			this.btnOk = (Button)base.FindName("btnOk");
			this.progress_outer = (Rectangle)base.FindName("progress_outer");
			this.progress_inner = (Border)base.FindName("progress_inner");
		}
	}
}
